home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / MoreFiles 1.2.1 / FileCopy.p < prev    next >
Encoding:
Text File  |  1994-07-22  |  5.4 KB  |  123 lines  |  [TEXT/PJMM]

  1. UNIT FileCopy;
  2.  
  3. {    Apple Macintosh Developer Technical Support                                }
  4. {                                                                            }
  5. {    FileCopy: A robust, general purpose file copy routine.                    }
  6. {    by Jim Luther, Apple Developer Technical Support                        }
  7. {                                                                            }
  8. {    File:        FileCopy.p                                                    }
  9. {                                                                            }
  10. {    Copyright © 1992-1994 Apple Computer, Inc.                                }
  11. {    All rights reserved.                                                    }
  12. {                                                                            }
  13. {    You may incorporate this sample code into your applications without        }
  14. {    restriction, though the sample code has been provided "AS IS" and the    }
  15. {    responsibility for its operation is 100% yours.  However, what you are    }
  16. {    not permitted to do is to redistribute the source as "DSC Sample Code"    }
  17. {    after having made changes. If you're going to re-distribute the source,    }
  18. {    we require that you make it clear in the source that the code was        }
  19. {    descended from Apple Sample Code, but that you've made changes.            }
  20.  
  21.  
  22. INTERFACE
  23.  
  24.  
  25. {***************************************************************************}
  26.  
  27.  
  28.     FUNCTION FileCopy (srcVRefNum: Integer;
  29.                                     srcDirID: LongInt;
  30.                                     srcName: Str255;
  31.                                     dstVRefNum: Integer;
  32.                                     dstDirID: LongInt;
  33.                                     dstPathname: StringPtr;
  34.                                     copyName: StringPtr;
  35.                                     copyBufferPtr: Ptr;
  36.                                     copyBufferSize: LongInt;
  37.                                     preflight: Boolean): OSErr;
  38. {    Use FileCopy to duplicate a file and optionally rename it.                }
  39. {    Since the PBHCopyFile routine is only available on some                    }
  40. {    AFP server volumes under specific conditions, this routine                }
  41. {    either uses PBHCopyFile, or does all of the work PBHCopyFile            }
  42. {    does.  The srcVRefNum, srcDirID and srcName are used to                    }
  43. {    determine the location of the file to copy.  The dstVRefNum                }
  44. {    dstDirID and dstPathname are used to determine the location of            }
  45. {    the destination directory.  If copyName <> NIL, then it points            }
  46. {    to the name of the new file.  If copyBufferPtr <> NIL, it                }
  47. {    points to a buffer of copyBufferSize that is used to copy                }
  48. {    the file's data.  The larger the supplied buffer, the                    }
  49. {    faster the copy.  If copyBufferPtr = NIL, then this routine                }
  50. {    allocates a buffer in the application heap. If you pass a                }
  51. {    copy buffer to this routine, make its size a multiple of 512            }
  52. {    ($200) bytes for optimum performance.                                    }
  53. {                                                                            }
  54. {    srcVRefNum        input:    Source volume specification.                    }
  55. {    srcDirID        input:    Source directory ID.                            }
  56. {    srcName            input:    Source file name.                                }
  57. {    dstVRefNum        input:    Destination volume specification.                }
  58. {    dstDirID        input:    Destination directory ID.                        }
  59. {    dstPathname        input:    Pointer to destination directory name, or        }
  60. {                            nil when dstDirID specifies a directory.        }
  61. {    copyName        input:    Points to the new file name if the file is        }
  62. {                            to be renamed or nil if the file isn't to        }
  63. {                            be renamed.                                        }
  64. {    copyBufferPtr    input:    Points to a buffer of copyBufferSize that        }
  65. {                            is used the i/o buffer for the copy or            }
  66. {                            nil if you want FileCopy to allocate its        }
  67. {                            own buffer in the application heap.                }
  68. {    copyBufferSize    input:    The size of the buffer pointed to                }
  69. {                            by copyBufferPtr.                                }
  70. {    preflight        input:    If true, FileCopy makes sure there are enough    }
  71. {                            allocation blocks on the destination volume to    }
  72. {                            hold both the data and resource forks before    }
  73. {                            starting the copy.                                }
  74.  
  75.  
  76. {***************************************************************************}
  77.  
  78.  
  79.     FUNCTION FSpFileCopy (srcSpec: FSSpec;
  80.                                     dstSpec: FSSpec;
  81.                                     copyName: StringPtr;
  82.                                     copyBufferPtr: Ptr;
  83.                                     copyBufferSize: LongInt;
  84.                                     preflight: Boolean): OSErr;
  85. {    Use FSpFileCopy to duplicate a file and optionally rename it.            }
  86. {    Since the PBHCopyFile routine is only available on some                    }
  87. {    AFP server volumes under specific conditions, this routine                }
  88. {    either uses PBHCopyFile, or does all of the work PBHCopyFile            }
  89. {    does.  The srcSpec is used to                                            }
  90. {    determine the location of the file to copy.  The dstSpec is                }
  91. {    used to determine the location of the                                    }
  92. {    destination directory.  If copyName <> NIL, then it points                }
  93. {    to the name of the new file.  If copyBufferPtr <> NIL, it                }
  94. {    points to a buffer of copyBufferSize that is used to copy                }
  95. {    the file's data.  The larger the supplied buffer, the                    }
  96. {    faster the copy.  If copyBufferPtr = NIL, then this routine                }
  97. {    allocates a buffer in the application heap. If you pass a                }
  98. {    copy buffer to this routine, make its size a multiple of 512            }
  99. {    ($200) bytes for optimum performance.                                    }
  100. {                                                                            }
  101. {    srcSpec            input:    An FSSpec record specifying the source file.    }
  102. {    dstSpec            input:    An FSSpec record specifying the destination        }
  103. {                            directory.                                        }
  104. {    copyName        input:    Points to the new file name if the file is        }
  105. {                            to be renamed or nil if the file isn't to        }
  106. {                            be renamed.                                        }
  107. {    copyBufferPtr    input:    Points to a buffer of copyBufferSize that        }
  108. {                            is used the i/o buffer for the copy or            }
  109. {                            nil if you want FileCopy to allocate its        }
  110. {                            own buffer in the application heap.                }
  111. {    copyBufferSize    input:    The size of the buffer pointed to                }
  112. {                            by copyBufferPtr.                                }
  113. {    preflight        input:    If true, FSpFileCopy makes sure there are        }
  114. {                            enough allocation blocks on the destination        }
  115. {                            volume to hold both the data and resource forks    }
  116. {                            before starting the copy.                        }
  117.  
  118.  
  119. {***************************************************************************}
  120.  
  121. IMPLEMENTATION
  122.  
  123. END.